<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html">
	<meta charset="utf-8" />
	<meta http-equiv="X-UA-Compatible" content="IE=edge" />
	<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
	<title></title>
</head>
<body erke-hide>
</body>
<script>
/**
 * @param {number[]} prices
 * @return {number}
 */
var maxProfit = function(prices) {
	var max=0;
	var sum=0,maxSum=0,stop;
    for(var i=prices.length-1;i>=0;i--){
		sum=0;
		stop=i;
		for(var j=stop;j>=0;j--){
			if(prices[stop]-prices[j]>0){
				max=prices[stop]-prices[j];
				sum+=max;
			};
             stop=j;
		};
		if(sum>maxSum){
			maxSum=sum;
		};
	};
	for(var i=prices.length-1;i>=0;i--){
		for(var j=i;j>=0;j--){
			if(prices[i]-prices[j]>maxSum){
				maxSum=prices[i]-prices[j];
			};
		};
	};
	console.log(maxSum);
	return maxSum;
};
var allenDie=new maxProfit([6,1,3,2,4,7]);
</script>
</html>
